﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MotionCS.Controller
{
    public class LeadshineCompare : ICompare
    {
        /// <summary>
        /// 比较器
        /// </summary>
        public ushort Hcmp;
        /// <summary>
        /// 比较模式
        /// </summary>
        public ushort Mode;
        /// <summary>
        /// 比较轴
        /// </summary>
        public ushort Axis;
        /// <summary>
        /// 比较源
        /// </summary>
        public ushort Source;
        /// <summary>
        /// 有效电平
        /// </summary>
        public ushort Logic;
        /// <summary>
        /// 有效时间
        /// </summary>
        public ushort Time;
        /// <summary>
        /// 初始化配置
        /// </summary>
        public void InitConfi()
        {
            Smc300Api.HcmpSetMode(Hcmp, Mode);
            Smc300Api.HcmpSetConfig(Hcmp, Axis, Source, Logic, Time);
        }
        /// <summary>
        /// 设置模式
        /// </summary>
        public void SetMode()
        {
            Smc300Api.HcmpSetMode(Hcmp, Mode);
        }
        /// <summary>
        /// 关闭比较器
        /// </summary>
        public void CloseMode()
        {
            Smc300Api.HcmpSetMode(Hcmp, 0);
            Smc300Api.HcmpAddPointUnit(Hcmp, 1);
        }
        /// <summary>
        /// 清除比较点
        /// </summary>
        public void ClearPoints()
        {
            Smc300Api.HcmpClearPoint(Hcmp);
        }
        /// <summary>
        /// 添加/更新比较点
        /// </summary>
        /// <param name="pos"></param>
        public void AddPoints(float[] pos, int num)
        {
            for (int i = 0; i < num; i++)
            {
                Smc300Api.HcmpAddPointUnit(Hcmp, pos[i]);
            }
        }
        /// <summary>
        /// 设置高速比较线性参数
        /// </summary>
        /// <param name="inc"></param>
        /// <param name="Count"></param>
        public void SetLiner(float inc, int Count)
        {
            Smc300Api.HcmpSetLinerUnit(Hcmp, inc, Count);
        }
        /// <summary>
        /// 设置比较端口导通
        /// </summary>
        public void CmpPinSetOn()
        {
            Smc300Api.WriteOutbit(10, 0);
        }
        /// <summary>
        /// 设置比较口断开
        /// </summary>
        public void CmpPinSetOff()
        {
            Smc300Api.WriteOutbit(10, 1);
        }
    }
}
